﻿package nl.stroep.classbuilder.app
{
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.utils.getTimer;
	import nl.stroep.classbuilder.cb.CbClass;
	import nl.stroep.classbuilder.cb.CbMethod;
	import nl.stroep.classbuilder.cb.CbParameter;
	import nl.stroep.classbuilder.codeformatter.CodeFormatter;
	import nl.stroep.classbuilder.definitions.AccessModifiers;
	import nl.stroep.classbuilder.definitions.FunctionModifier;
	
	/**
	 * ...
	 * @author Mark Knol
	 */
	public final class TestCodeIndent extends Sprite 
	{
		
		public function TestCodeIndent():void 
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			// entry point
			
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			
			var formatted:String =  CodeFormatter.format("object{object{object{}}}");
			formatted =  CodeFormatter.format(formatted);
			trace(formatted)
			
			create();
		}
		
		private function create():void
		{
			var startTime:Number = getTimer();
			
			// create global class functions
			
			var params:Vector.<CbParameter> = new Vector.<CbParameter>;
			params.push( new CbParameter("id","int" ) );
			params.push( new CbParameter("name", "String", null, false ) );
			params.push( new CbParameter("data", "Object", "null", true ) );
			
			var myFunc1:CbMethod = new CbMethod("doSomething", "void", params);
			
			var myFunc3:CbMethod = new CbMethod("addChild", "Sprite", null, AccessModifiers.PUBLIC, FunctionModifier.OVERRIDE, "for(var i:uint = 0; i < 10; i++)\n{\n // test \n}");
			
			var myFunctions:Vector.<CbMethod> = new Vector.<CbMethod>();
			myFunctions.push(myFunc1);
			myFunctions.push(myFunc3);
			
			// create final class
			var cbClass:CbClass = new CbClass("MyClass", myFunctions);
			
			
			
			trace("Calculated vo in ", getTimer() - startTime, "ms");
			
			var textfield:TextField = new TextField()
			textfield.defaultTextFormat = new TextFormat("Consolas", 11, 0, false);
			textfield.condenseWhite = true;
			textfield.text = CodeFormatter.format( cbClass.toString() );
			textfield.wordWrap = true;
			textfield.width = stage.stageWidth;
			textfield.height = textfield.textHeight + 10;
			this.addChild(textfield);
		}
		
		
	}
	
}